<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>工单</title>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
</head>

<body>
    <div class="mui-content">
        <ul class="mui-table-view01">
            <li class="search-cell">
                <div class="mui-input-row mui-search">
                    <input type="search" id="searchText" onclick="openSearchWin()" readonly="readonly" class="mui-input-clear" placeholder="请输入关键字"><span class="mui-icon mui-icon-clear mui-hidden"></span><span class="mui-placeholder"><span></span></span>
                </div>
                <div class="mui-btn mui-btn-primary" tapmode onclick="openTastWin('work_order_manage','工单管理',{
					type: 'orderList',
	    			orderType: '',
	    			searchText:$api.val($api.byId('searchText'))
				})">
                    搜索
                </div>
            </li>
        </ul>
        <ul class="mui-table-view work_order_list" id="ordrListsContent">
            <script type="text/template" id="itemslist">
                {{each datas as item i}}
                <li class="mui-table-view-cell" onclick="openOrderWin('{{item.worktype}}')">
                    <div class="mui-table mui-navigate-right">
                        <div class="mui-table-cell mui-col-xs-8">
                            <h4 class="mui-ellipsis">{{item.worktype}}</h4>
                            <p class="mui-h6 mui-ellipsis-2">{{item.orderDesc}}</p>
                        </div>
                        <div class="mui-table-cell mui-col-xs-4 mui-text-right">
                            <span class="mui-badge mui-badge-warning">{{item.incomplete}}/{{item.complete}}</span>
                        </div>
                    </div>
                </li>
                {{/each}}
            </script>
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script src="../script/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/common.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/template.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var page = 1;
    var loadEnd = false;
    var UISearchBar = null;
    apiready = function() {
        UISearchBar = api.require('UISearchBar');
        onloadData(page, false);
        scrollToBottomHandler(function() {
            if (!loadEnd) { // 没有结束时继续加载
                page++;
                onloadData(page, true);
            } else { // 告诉到底了
                EndToast('到底了');
            }
        })
        Refresh(function() {
            loadEnd = false;
            page = 1;
            onloadData(page, false);
        });
    }

    function onloadData(page, load) {
        var getToken = $api.getStorage('partsInfo');
        if (getToken) {
            ajaxrd("queryOrderTypeList", {
                token: getToken.token,
                pageNo: page,
                pageSize: 10
            }, function(ret, err) {
                api.refreshHeaderLoadDone();
                AddData('itemslist', 'ordrListsContent', ret.list, load);
                if (ret.list.length < 10) {
                    loadEnd = true
                }

            })
        } else {
            api.openWin({
                name: 'login',
                url: './login.html'
            });
        }
    }

    function openOrderWin(name) {
        openWin('work_order_manage', name + '/工单管理', {
            background: '#6098de',
            color: '#fff'
        }, {
            type: 'orderList',
            orderType: name
        })
    }

    function openSearchWin() {
        UISearchBar.open({
            placeholder: '请输入搜索关键字',
            historyCount: 10,
            showRecordBtn: false,
            dataBase: 'workOrder',
            texts: {
                cancelText: '取消',
                clearText: '清除搜索记录'
            },
            styles: {
                navBar: {
                    bgColor: '#3398dc',
                    borderColor: '#ccc'
                },
                searchBox: {
                    bgImg: '',
                    color: '#000',
                    height: 35,
                    size: 13
                },
                cancel: {
                    bg: 'rgba(0,0,0,0)',
                    color: '#fff',
                    size: 15
                },
                list: {
                    color: '#696969',
                    bgColor: '#FFFFFF',
                    borderColor: '#eee',
                    size: 15
                },
                clear: {
                    color: '#000000',
                    borderColor: '#ccc',
                    size: 15
                }
            }
        }, function(ret, err) {
            if (ret && (ret.eventType == 'search' || ret.eventType == 'history')) {
                openTastWin('work_order_manage', '工单管理', {
                    type: 'orderList',
                    orderType: '',
                    searchText: ret.text
                })
            } else {
                //alert(JSON.stringify(err));
            }
        });
    }
</script>

</html>
